<template>
  <div>
    <el-dialog
      v-model="dialogVisible"
      width="80%"
      align-center
      :show-close="false"
      @close="handleClose"
      destroy-on-close
      draggable
    >
      <template #header="{ close }">
        <div class="dialog-header flex justify-between items-center">
          <div>项目查看</div>
          <el-icon class="el-icon--left cursor-pointer" @click="close"
            ><CircleCloseFilled color="#fff"
          /></el-icon>
        </div>
      </template>
      <div class="flex">
        <el-tabs v-model="activeTabName" class="flex-1">
          <el-tab-pane label="项目信息" name="0"></el-tab-pane>
          <el-tab-pane label="项目成员" name="1"></el-tab-pane>
          <el-tab-pane label="项目预算" name="2"></el-tab-pane>
          <el-tab-pane label="项目经费" name="3"></el-tab-pane>
          <el-tab-pane label="项目文档" name="4"></el-tab-pane>
          <el-tab-pane label="衍生成果" name="5"></el-tab-pane>
          <el-tab-pane label="执行过程" name="6"></el-tab-pane>
        </el-tabs>
        <el-link
          type="primary"
          v-if="procInsId"
          class="bg-white pr-[10px]"
          @click="checkHistoryModalVisible = true"
          >审核记录</el-link
        >
      </div>
      <ProjectBaseInfo v-if="activeTabName != 0" />
      <ProjectInfo v-if="activeTabName == 0" />
      <ProjectMember v-if="activeTabName == 1" />
      <ProjectBudget v-if="activeTabName == 2" />
      <FeeInfo v-if="activeTabName == 3" />
      <ProjectDocument v-if="activeTabName == 4" />
      <AchievementInfo v-if="activeTabName == 5" />
      <ProcessInfo v-if="activeTabName == 6" />
      <template #footer>
        <div class="dialog-footer">
          <div class="operate-btns">
            <el-button type="primary" @click="dialogVisible = false">关闭</el-button>
          </div>
        </div>
      </template>
    </el-dialog>
  </div>
  <CheckHistoryModal
    v-model="checkHistoryModalVisible"
    :procInsId="procInsId"
    :checker="checker"
    :checkDate="checkDate"
  />
</template>

<script setup>
import CheckHistoryModal from "@/views/project/components/CheckHistoryModal.vue";
import { baseInfo } from "@/api/project/zx/lxxm";
import ProjectBaseInfo from "./ProjectBaseInfo.vue";
import ProjectInfo from "./ProjectInfo.vue";
import ProjectMember from "./ProjectMember.vue";
import ProjectBudget from "./ProjectBudget.vue";
import ProjectDocument from "./ProjectDocument.vue";
import FeeInfo from "@/views/project/components/FeeInfo.vue";
import AchievementInfo from "@/views/project/components/AchievementInfo.vue";
import ProcessInfo from "@/views/project/components/ProcessInfo.vue";
import useCommonFetch from "@/hooks/useCommonFetch";
import useDictFetch from "@/hooks/useDictFetch";
/**获取公共下拉数据开始*/
const memberTypeList = useCommonFetch("成员类型");
const unitList = useCommonFetch("成果归属单位");
const allUnitList = useCommonFetch("所有单位");
const projectTypeList = useCommonFetch("项目分类（校级）");
const projectStatusList = useCommonFetch("项目状态");
const tjgsList = useCommonFetch("教育部统计归属");
const jjfwmbList = useCommonFetch("社会经济服务目标");
const hzTypeList = useCommonFetch("合作形式");
const gmjjhyList = useCommonFetch("国民经济行业");
const applierTitleList = useCommonFetch("职称");
const degreeList = useCommonFetch("学位");
const cdTypeList = useCommonFetch("项目-承担角色");
const checkStatusList = useDictFetch("bpm_process_instance_status"); //审核状态
provide("memberTypeList", memberTypeList);
provide("unitList", unitList);
provide("allUnitList", allUnitList);
provide("projectTypeList", projectTypeList);
provide("projectStatusList", projectStatusList);
provide("tjgsList", tjgsList);
provide("jjfwmbList", jjfwmbList);
provide("hzTypeList", hzTypeList);
provide("gmjjhyList", gmjjhyList);
provide("applierTitleList", applierTitleList);
provide("degreeList", degreeList);
provide("cdTypeList", cdTypeList);
provide("checkStatusList", checkStatusList);
/**获取公共下拉数据结束*/
const dialogVisible = ref(false);
const activeTabName = ref("0");
const operateId = ref(null);
provide("id", operateId);
const checkHistoryModalVisible = ref(false);
const procInsId = ref(null); //流程实例id
const checker = ref("");
const checkDate = ref("");
//获取基本信息
const getBaseInfoData = async () => {
  try {
    const params = {
      proId: operateId.value,
    };
    const res = await baseInfo(params);
    checkDate.value = res.data.checkDate;
    checker.value = res.data.checker;
    procInsId.value = res.data.processInstanceId;
  } catch (error) {
    console.log(error);
  }
};
//查看
const view = (id) => {
  operateId.value = id;
  dialogVisible.value = true;
  getBaseInfoData();
};
defineExpose({ view });
//关闭弹窗
const handleClose = () => {
  activeTabName.value = "0";
};
</script>

<style scoped lang="scss">
@import url("@/views/project/index.scss");
:deep(.el-tabs__header) {
  padding-left: 10px;
  margin-bottom: 0;
  background: #fff;
}
</style>
